<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head th:replace="~{_fragment :: head(title='博客列表')}">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width initial-scale=1.0">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/semantic-ui/2.2.10/semantic.min.css">
    <link rel="stylesheet" href="../../static/css/me.css" th:href="@{/css/me.css}">
    <title>博客列表</title>
</head>
<body>


<!--导航-->
<nav class="ui inverted attached segment" th:replace="~{_fragment :: nav(n=1)}">
</nav>

<!--中间内容-->

<p id="span"></p>

<div class="ui  container m-padded-tb-massive">
    <div class="ui secondary segment form">

        <form class="ui segment form">
            <div class="ui fields inline">
                <div class="field">
                    <input type="text" name="keytitle" id="keytitle" placeholder="标题">
                </div>
                <div class="field">
                    <!--                下拉效果-->
                    <div class="ui selection dropdown ">
                        <input type="hidden" name="keytid" id="keytid">
                        <i class="teal dropdown icon"></i>
                        <div class="default text">分类</div>
                        <div class="ui menu">
                            <th:block th:if="${typelist != null}">
                                <div class="item" th:each="type:${typelist}" th:data-value="${type.id}" th:text="${type.name}"></div>
                            </th:block>

                        </div>
                    </div>
                </div>

                <div class="field">
                    <div class="ui checkbox">
                        <input type="checkbox" id="recommend" name="keyrecommend">
                        <label for="recommend">推荐</label>
                    </div>
                </div>

                <div class="field">
                    <button th:id="search-btn" class="ui teal button mini basic" id="search-brn"><i class="icon search"></i>搜索</button>
                </div>
                <div class="field">
                    <button th:id="all-btn" class="ui teal button mini basic" id="all-btn"><i class="icon search"></i>全部博客</button>
                </div>
            </div>

        </form>


        <div>

            <table th:fragment="bloglist" class="ui compact teal table" th:id="blogtable">
                <thead>
                <tr>
                    <td>序号</td>
                    <td>标题</td>
                    <td>类型</td>
                    <td>推荐</td>
                    <td>状态</td>
                    <td>更新时间</td>
                    <td>操作</td>
                </tr>
                </thead>


                <th:block th:if="${jsonResult != null}">
                <tbody>
                    <input th:id="json-input" type="hidden" th:value="${jsonResult}">
                    <tr th:each="blog,bstat :${jsonResult.data.data}">
                        <td th:text="${bstat.count}"></td>
                        <td th:text="${blog.title}">博客标题</td>
                        <td th:text="${blog.type.name}">类型</td>
                        <td th:text="${blog.recommend} ? '是':'否'">是</td>
                        <td th:text="${blog.published} ?'发布':'草稿'">发布</td>
                        <td th:text="${#dates.format(blog.updateDate,'yyyy-MM-dd')}"></td>
                        <td>
                            <a href="#" th:href="@{/admin/blogInput/{bid}(bid=${blog.id})}" class="ui mini teal basic button">编辑</a>
                            <a href="#" th:href="@{/admin/deleteBlog/{bid}(bid=${blog.id})}"  onclick="return confirm('确定要删除该吗？三思啊! 删了可就没了！')" class="ui mini red basic button">删除</a>
                        </td>
                    </tr>
                </tbody>

                    <tfoot>
                    <tr>
                        <th colspan="7">
                            <div class="ui mini pagination menu"  >
                                <div class="ui button item"><a  th:id="first-btn" onclick="ajaxfunc(this)" th:attr="data-curr=1">首页</a></div>
                                <div class="ui button item"><a  th:id="pre-btn" onclick="ajaxfunc(this)" th:attr="data-curr=${jsonResult.data.prePage}">上一页</a></div>
                                <div class="ui button item"><a  th:id="next-btn" onclick="ajaxfunc(this)" th:attr="data-curr=${jsonResult.data.nextPage}">下一页</a></div>
                                <div class="ui button item"><a  th:id="last-btn" onclick="ajaxfunc(this)" th:attr="data-curr=${jsonResult.data.totalPage}">尾页</a></div>
                            </div>
                            <a  th:href="@{/admin/blogInput}" class="ui mini right floated teal basic button">新增</a>
                        </th>
                    </tr>
                    </tfoot>

                </th:block>



            </table>
        </div>

    </div>
</div>

<!--footer-->


<footer th:replace="~{_fragment :: footer}" class="ui inverted vertical segment">

<!--    <div class="ui center aligned container m-padded-tb-massive">-->
<!--        &lt;!&ndash;        grid将footer分为16&ndash;&gt;-->
<!--        <div class="ui grid divided inverted">-->
<!--            &lt;!&ndash;            wide填满&ndash;&gt;-->
<!--            <div class="three wide column">-->
<!--                <img src="../../static/images/weichat.png" th:src="/images/weichat.png" class="image ui rounded" style="width:110px;height:110px">-->
<!--            </div>-->
<!--            <div class="three wide column">-->
<!--                <h4 class="ui inverted header">最新博客</h4>-->
<!--                <div class="ui inverted link list " >-->
<!--                    <a href="#" class="item">用户故事</a>-->
<!--                    <a href="#" class="item">用户故事</a>-->
<!--                    <a href="#" class="item">用户故事</a>-->
<!--                </div>-->
<!--            </div>-->
<!--            <div class="three wide column">-->
<!--                <h4 class="ui inverted header">最新博客</h4>-->
<!--                <div class="ui inverted link list">-->
<!--                    <a href="#" class="item">用户故事</a>-->
<!--                    <a href="#" class="item">用户故事</a>-->
<!--                    <a href="#" class="item">用户故事</a>-->
<!--                </div>-->
<!--            </div>-->
<!--            <div class="seven wide column">-->
<!--                <h4 class="ui inverted header">最新博客</h4>-->
<!--                <p>这里是一些其他信息</p>-->
<!--            </div>-->


<!--        </div>-->

<!--        <div class="ui inverted section divider"></div>-->
<!--        <p>关于法律信息</p>-->
<!--    </div>-->
</footer>

<th:block th:replace="~{_fragment :: script}">
</th:block>

<script type="text/javascript">
$(function () {
    //在一开始时，不需要回传任何参数。查询所有的博客即可
    $.ajax({
        url:"/admin/listBlog",
        type:"get",
        success:function (res) {
            $('#blogtable').html(res);
    }
    })

});


var keytitle=$("#keytitle").val();
var keyrecommend=$("#keyrecommend").val();
var keytid=$("#keytid").val();




// 分页查询
function ajaxfunc(curr){
    var currentPage=$(curr).data("curr");
    $.ajax({
        url:"/admin/listBlog",
        type:"get",
        data:{
            "keytitle":keytitle,
            "keytid":keytid,
            "keyrecommend":keyrecommend,
            "currentPage":currentPage,
        },
        success:function (res) {
            $('#blogtable').html(res);
        }
    })
}



// 按条件查询
$('#search-btn').click(function () {
     keytitle=$("#keytitle").val();
     keyrecommend=$("#keyrecommend").val();
     keytid=$("#keytid").val();
    $.ajax({
        url:"/admin/listBlog",
        type:"get",
        data:{
            "keytitle":keytitle,
            "keytid":keytid,
            "keyrecommend":keyrecommend,
        },
        success:function (res) {
            $('#blogtable').html(res);

        }

    })
});

// 查询全部的博客
$('#all-btn').click(function () {
    keytitle=null;
    keyrecommend=null;
    keytid=null;
    $.ajax({
        url:"/admin/listBlog",
        type:"get",
        data:{
            "keytitle":keytitle,
            "keytid":keytid,
            "keyrecommend":keyrecommend,
        },
        success:function (res) {
            $('#blogtable').html(res);

        }

    })
});







</script>

</body>
</html>